package com.theme.passport.service.theme.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.utils.Query;
import com.theme.passport.dao.theme.AlbumDao;
import com.theme.passport.entity.theme.AlbumEntity;
import com.theme.passport.service.theme.AlbumService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("albumService")
public class AlbumServiceImpl extends ServiceImpl<AlbumDao, AlbumEntity> implements AlbumService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String type = (String) params.get("type");
        String keyword = (String) params.get("key");
        String status = (String) params.get("status");

        IPage<AlbumEntity> page = this.page(
                new Query<AlbumEntity>().getPage(params),
                new QueryWrapper<AlbumEntity>()
                        .eq(StringUtils.isNotBlank(type),"type", type)
                        .eq(StringUtils.isNotBlank(status), "status", status)
                        .like(StringUtils.isNotBlank(keyword), "name", keyword)
                        .orderByDesc("created")
        );

        return new PageUtils(page);
    }

}